﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using JustinAngel.MetroBlog.Common.IoC;
using JustinAngel.MetroBlog.Models;
using JustinAngel.MetroBlog.Services.CategoryService;
using JustinAngel.MetroBlog.Services.Data;
using JustinAngel.MetroBlog.Services.Repository;
using Microsoft.Practices.Unity;
using JustinAngel.MetroBlog.Common.Helpers;

namespace JustinAngel.MetroBlog.Controllers
{
    public class SidebarJavascriptController : Controller
    {
        public SidebarJavascriptController()
        {
            IoC.BuildUp(this);
        }

        [Dependency]
        public IRepository<Category> CategoryRepository { get; set; }

        [Dependency]
        public IRepository<BlogPost> BlogPostRepository { get; set; }

        [OutputCache(Duration = 60 * 15, VaryByParam = "none")]
        public ActionResult Show()
        {
            var model = new SidebarJavascriptModel()
                {
                    Categories = CategoryRepository.Get().ToList(),
                    Articles = BlogPostRepository.Get().OrderByDescending(b => b.DateCreated).ToList(),
                };

            this.SetWebsiteRoot();

            return View("SidebarJavascript", model);
        }

    }
}
